package com.zhentao.subscription.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhentao.subscription.domain.entity.SubscriptionTask;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface SubscriptionTaskMapper extends BaseMapper<SubscriptionTask> {

    /**
     * 分页查询任务列表（支持关键字搜索）
     */
    @Select("<script>" +
            "SELECT * FROM sub_task " +
            "WHERE is_delete = 0 " +
            "<if test='keyword != null and keyword != \"\"'>" +
            "  AND (task_name LIKE CONCAT('%', #{keyword}, '%') " +
            "       OR customs_code LIKE CONCAT('%', #{keyword}, '%'))" +
            "</if>" +
            "ORDER BY created_time DESC" +
            "</script>")
    IPage<SubscriptionTask> selectPageWithKeyword(Page<SubscriptionTask> page, @Param("keyword") String keyword);
}

